class CustomError extends Error {
  constructor(code, message) {
    super(message)
    this.code = code
    this.name = 'CustomError'
  }
}

class NotFoundError extends CustomError {
  constructor(message = '资源不存在') {
    super(404, message)
  }
}

class AuthError extends CustomError {
  constructor(message = '未授权访问') {
    super(401, message)
  }
}

class ForbiddenError extends CustomError {
  constructor(message = '禁止访问') {
    super(403, message)
  }
}

class ValidationError extends CustomError {
  constructor(message = '参数校验失败') {
    super(422, message)
  }
}
class ApiError extends Error {
  constructor({ code = 500, message = 'Internal Server Error', details, expose = false }) {
    super(message)
    this.name = this.constructor.name
    this.code = code
    this.details = details
    this.expose = expose
    Error.captureStackTrace(this, this.constructor)
  }
}

module.exports = {
  CustomError,
  NotFoundError,
  AuthError,
  ForbiddenError,
  ValidationError,
  ApiError,
}
